Group array of objects into 2D arrays based on nested value